﻿/// <reference path="../../Scripts/commen_js/MJ_JSComment.js" />

var indexobject = {
    getdata: function (where) {
        poststr = "{\"type\":\"indexdata\",\"htmldata\":\"" + where + "\"}";
        this.postajaxs(poststr, this.showdata);
    },
    postajaxs: function (postdata, fangfa) {
        mj_ajax("../Handler1.ashx", "json", postdata, fangfa)
    },
    showdata: function (data) {
        if (data.result == "ok") {
            var datatable = data.table;
            var product_spsx = document.getElementById("product_spsx");
            $("#product_spsx").empty();
            for (var i = 0; i < datatable.length; i++) {
                var tr = document.createElement("tr");
                var td = document.createElement("td");
                var div = document.createElement("div");
                td.id = datatable[i].product_id;
                td.onclick = function () {
                    indexobject.productdetale(this.id);
                }
                var img1 = document.createElement("img");
                img1.addClass = "img img-responsive";
                img1.src = "../" + datatable[i].main_img;
                var p1 = document.createElement("p");
                p1.innerHTML =datatable[i].product_name;
                var p2 = document.createElement("p");
                p2.className = "product_price";
                p2.innerHTML = "价格："+datatable[i].price;
                div.appendChild(img1);
                div.appendChild(p1);
                div.appendChild(p2);
                td.appendChild(div);
               
                var addone = i+1;
                if (addone < datatable.length) {
                    var td1 = document.createElement("td");
                    var div1 = document.createElement("div");
                    td1.id = datatable[i + 1].product_id;
                    td1.onclick = function () {
                        indexobject.productdetale(this.id);
                    }
                    var img11 = document.createElement("img");
                    img11.addClass = "img img-responsive";
                    img11.src = "../" + datatable[i + 1].main_img;
                    var p11 = document.createElement("p");
                    p11.innerHTML = datatable[i + 1].product_name;
                    var p21 = document.createElement("p");
                    p21.className = "product_price";
                    p21.innerHTML = "价格：" + datatable[i + 1].price;
                    i++;
                    div1.appendChild(img11);
                    div1.appendChild(p11);
                    div1.appendChild(p21);
                    td1.appendChild(div1);
                    tr.appendChild(td);
                    tr.appendChild(td1);
                    product_spsx.appendChild(tr);
                   
                }
                else {
                    tr.appendChild(td);
                    product_spsx.appendChild(tr);
                }
               
            }

        }
        else {
            alert(data.msg)
            ;
        }

    },
    productdetale:function(productid){
        location.href = "About.aspx?" + "productid=" + productid + "&r=" + Math.random();
    },
    getopenid: function () {
        var code = GetQueryString("code");
        var openid = $.cookie("openid");
       // $.cookie("openid", "orG7Tvl7KOwM90AbVUcUVhhcfpCg");
        if (!isUndefinedNullOrEmpty(code)) {
            poststr = "{\"type\":\"getopenid\",\"code\":\"" + code + "\"}";
            this.postajaxs(poststr, this.getopenidresult);
        }
    },
    getopenidresult: function (data) {
        if (data.result == "ok") {
            if (!isUndefinedNullOrEmpty(data.msg)) {
                $.cookie("openid", data.msg);
            }
        }
    },
    changestyle: function (id) {
        var ff = id;
        $("#spsxs").removeClass("table_a");
        $("#hdrxs").removeClass("table_a");
        $("#dztjs").removeClass("table_a");
        $("#tjsps").removeClass("table_a");
        $("#" + id + "").addClass("table_a"); //添加样式
    },
};

